package pe.com.trener.layer.model.persistence.daoimpl;

/**
 * @author:   Oscar Erick Candela Carbajal
 * @rol:	  Analista Programador
 * @proyecto: Portal Trener
 *
 */

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import org.apache.struts.util.LabelValueBean;
import org.springframework.orm.hibernate3.HibernateTemplate;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import pe.com.trener.layer.model.persistence.dao.TrimestreDao;
import pe.com.trener.layer.model.pojo.Trimestre;

public class TrimestreDaoImpl extends HibernateDaoSupport implements TrimestreDao {

	@SuppressWarnings("unchecked")
	public List<Trimestre> buscarTodos() throws Exception {
		try {   
			List<Trimestre> resultQuery = new ArrayList<Trimestre>();
			List resultLabelValue = new ArrayList();
			HibernateTemplate ht = getHibernateTemplate();
		 		        
	        String queryString = " from " +
								 " Trimestre o " +
								 " where " +
								 " 		o.estado = 1 ";
	        
	        resultQuery = (List<Trimestre>)ht.find(queryString);
	        	        
	        Iterator<Trimestre> it = resultQuery.iterator();
	        
	        while (it.hasNext()) {
	        	Trimestre objectModel = (Trimestre)it.next();
	        	LabelValueBean objectLabelValueBean = new LabelValueBean();
	        	objectLabelValueBean.setLabel(objectModel.getDescripcion());
	        	objectLabelValueBean.setValue(objectModel.getCodigoTrimestre().toString());
	        	resultLabelValue.add(objectLabelValueBean);
	        }
	        return resultLabelValue;
		} catch(Exception e) {
			e.printStackTrace();
			throw new Exception(e);
		} finally {		
		}        
	}
	
}